package com.jtbd.dto.http;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jtbd.domain.UserInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@Schema(description = "用户基础信息")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserInfoHttpDto {
    @Schema(description = "用户id")
    private Long id;
    @Schema(description = "用户类型 1:学生 2：家长 3：员工")
    @NotNull
    private Integer userType;
    @Schema(description = "用户名")
    @NotNull
    private String username;
    @Schema(description = "手机号")
    @NotBlank
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式错误")
    private String phone;
    @Schema(description = "密码")
    @NotBlank
    private String password;
    @Schema(description = "头像")
    private String avatar;
    @Schema(description = "邮箱")
    private String email;
    @Schema(description = "昵称")
    private String nickname;
    @Schema(description = "性别：0未知 1男 2女")
    private Integer sex;
    @Schema(description = "生日")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthday;
    @Schema(description = "年龄")
    private Integer age;
    @Schema(description = "地址")
    private String address;
    @Schema(description = "创建人")
    private Long createId;
    @Schema(description = "修改人")
    private Long updateId;

    @Schema(hidden = true)
    public static UserInfo getUserInfo(UserInfoHttpDto httpDto) {
        return UserInfo.builder().id(httpDto.id).userType(httpDto.userType).username(httpDto.username).phone(httpDto.phone).password(httpDto.password).avatar(httpDto.avatar).email(httpDto.email).nickname(httpDto.nickname).sex(httpDto.sex).birthday(httpDto.birthday).age(httpDto.age).address(httpDto.address).createId(httpDto.createId).updateId(httpDto.updateId).build();
    }

    public static UserInfoHttpDto getUserInfoHttpDto(UserInfo userInfo) {
        return UserInfoHttpDto.builder().id(userInfo.getId()).userType(userInfo.getUserType()).username(userInfo.getUsername()).phone(userInfo.getPhone()).password(userInfo.getPassword()).avatar(userInfo.getAvatar()).email(userInfo.getEmail()).nickname(userInfo.getNickname()).sex(userInfo.getSex()).birthday(userInfo.getBirthday()).age(userInfo.getAge()).address(userInfo.getAddress()).createId(userInfo.getCreateId()).updateId(userInfo.getUpdateId()).build();
    }
}
